package me.pplay.playtalk.util;

import java.io.IOException;

import me.pplay.playtalk.data.Globals;
import android.media.MediaRecorder;

public class AudioRecorder {
	private MediaRecorder recorder;
	public AudioRecorder(){
		recorder = new MediaRecorder();
	}
	/**
	 * 
	 * @return 返回文件path
	 */
	public String startAudioRecorder() {
		String filePath	= null;
		try {
			filePath	= Globals.FILE_PATH_AUDIO + System.currentTimeMillis()+".AMR";
			recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
			recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
			recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
			recorder.setOutputFile(filePath);
			recorder.prepare();
			recorder.start();
		} catch (IllegalStateException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return filePath;
	}
	
	public void stopAudioRecorder(){
		recorder.release();
		recorder = null;
	}

}
